package com.Hsu.book.config;

import com.Hsu.book.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;

/**
 * @author Hsu琛君珩
 * @ClassName:WebConfig
 * @date 2024-01-07
 * @apiNote
 * @Version: v1.0
 */

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    //包含一些不应该被拦截的的URL路径
    private static List<String> excludePath = Arrays.asList(
            "/user/login",//排除这个特定的路径
            //因为我们写的不是完全的前后端分离
            //下面是为了拦截前端部分的静态资源
            "/css/**",
            "/js/**",
            "/pic/**",
            "/**/*.html",
            "/test/**");

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)//添加了拦截器
                .addPathPatterns("/**")//  /**表示给所有方法添加拦截器，即匹配所有路径
                .excludePathPatterns(excludePath);
    }
}
